<template>
  <div class="confirm" :class="{ fade }">
    <div class="wrapper">
      <div class="header">
        <h3>{{ props.title }}</h3>
        <a href="JavaScript:;" class="iconfont icon-close-new"></a>
      </div>
      <div class="body">
        <i class="iconfont icon-warning"></i>
        <span>{{ props.text }}</span>
      </div>
      <div class="footer">
        <Button size="mini" type="gray" @click="cancel">取消</Button>
        <Button size="mini" type="primary" @click="submit">确认</Button>
      </div>
    </div>
  </div>
</template>
  <script>
export default {
  name: 'Confirm'
}
</script>
<script setup>
import Button from './button.vue'
import { ref, onMounted } from 'vue';
const props = defineProps({
  title: {
    type: String,
    default: '温馨提示'
  },
  text: {
    type: String,
    default: '您确认从购物车删除该商品吗？'
  },
  cancelCallback: Function,
  submitCallback: Function
})

// 对话框默认隐藏
const fade = ref(false)
// 组件渲染完毕后
onMounted(() => {
  // 过渡效果需要在元素创建完毕后延时一会加上才会触发
  setTimeout(() => {
    fade.value = true
  }, 0)
})
// 取消
const cancel = () => {
  // 其他事情
  props.cancelCallback()
}
// 确认
const submit = () => {
  // 其他事情
  props.submitCallback()
}
</script>
  <style scoped lang="scss">
  .confirm {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 8888;
    background: rgba(0, 0, 0, .5);
  
    .wrapper {
      width: 400px;
      background: #fff;
      border-radius: 4px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
  
      .header,
      .footer {
        height: 50px;
        line-height: 50px;
        padding: 0 20px;
      }
  
      .body {
        padding: 20px 40px;
        font-size: 16px;
  
        .icon-warning {
          color: $priceColor;
          margin-right: 3px;
          font-size: 16px;
        }
      }
  
      .footer {
        text-align: right;
  
        .button {
          margin-left: 20px;
        }
      }
  
      .header {
        position: relative;
  
        h3 {
          font-weight: normal;
          font-size: 18px;
        }
  
        a {
          position: absolute;
          right: 15px;
          top: 15px;
          font-size: 20px;
          width: 20px;
          height: 20px;
          line-height: 20px;
          text-align: center;
          color: #999;
  
          &:hover {
            color: #666;
          }
        }
      }
    }
  }
  </style>